5 ' Programmed fun #1 by Ross A. Wirth
10 ' Title -- 12 digits of fun
15 ' Sample solution using recursive calls
20 ' 
25 AN=26
30 L=0:F2$="##":F3$="###":C=0:AC=0:TC=0:J=0:X$="   ":X=0:Y=0
35 DIM I(12),A(220,12),SP(12)
40 CLS
45 I(0)=0
47 GOSUB 400 ' setup screen
50 GOSUB 100
55 CLS
57 PRINT "The 12 digit answers are:"
58 PRINT
60 FOR J=1 TO TC
61  L=J
62  IF L>220 THEN L=L-220:GOTO 85
63  PRINT J; ":  ";
65  FOR L=1 TO 12
70   PRINT A(J,L);
75  NEXT
80  PRINT:PRINT
85 NEXT
87 PRINT TC;" answers"
90 END
100 L=L+1
105 PRINT @7," ";:PRINT USING F3$;L;
110 I(L)=0
115 I(L)=I(L)+1
117 GOSUB 180:PRINT@SP(L)," ";:PRINT USING F2$;I(L);
118 IF I(L)>12 THEN 333
120 ' test to see if digit is already used
130 C=0
140 FOR J=0 TO (L-1)
150  IF I(L)=I(J) THEN C=C+1
160 NEXT
170 IF C>0 THEN 330
173 GOTO 270
175 '  test to see how "26" is formed
180 ON L GOTO 250,250,250,190,250,250,200,205,250,215,250,220
190 X=I(1) +I(2) +I(3) +I(4) -AN:GOSUB 700:GOTO 250
200 X=I(2) +I(3) +I(6) +I(7) -AN:GOSUB 700:GOTO 250
205 X=I(5) +I(6) +I(7) +I(8) -AN:GOSUB 700
210 X=I(1) +I(4) +I(5) +I(8) -AN:GOSUB 700:GOTO 250
215 X=I(9) +I(2) +I(6) +I(10)-AN:GOSUB 700:GOTO 250
220 X=I(11)+I(3) +I(7) +I(12)-AN:GOSUB 700
230 X=I(9) +I(10)+I(11)+I(12)-AN:GOSUB 700
250 RETURN
270 IF L=12 THEN 310
280 GOSUB 100
290 GOTO 330
300 ' new answer found
310 AC=AC+1:TC=TC+1:PRINT@20,TC;
312 IF AC>220 THEN AC=1
313 PRINT@71," ";:PRINT USING F3$;AC;
315 FOR II=1 TO 12
320  A(AC,II)=I(II)
325 NEXT
330 IF I(L)<12 THEN 115
333 I(L)=0
335 PRINT@SP(L)," ";:PRINT USING F2$;I(L);
340 L=L-1 ' back out of the recursion
345 PRINT@7," ";:PRINT USING F3$;L;
350 RETURN
400 ' setup screen
410 DATA 283,475,667,859,294,486
420 DATA 678,870,464,497,656,689
430 FOR I=1 TO 12:READ SP(I):NEXT
440 DATA A1,B2,B3,A4,A5,B6,B7,A8,C9,C10,C11,C12
450 FOR I=1 TO 12
460  READ X$
470  PRINT@(SP(I)-67),X$;
475 NEXT
480 FOR X=24 TO 113
490  FOR Y=7 TO 43 STEP 9
495   IF (X>45)AND(X<92) THEN 510
500   IF (Y=7)OR(Y=43) THEN 520
510   SET(X,Y)
520  NEXT
530 NEXT
540 FOR Y=8 TO 42
550  FOR X=24 TO 112 STEP 22
555   IF (Y>15)AND(Y<35) THEN 570
560   IF (X<46)OR(X>91) THEN 580
570   SET(X,Y):SET(X+1,Y)
580  NEXT
590 NEXT
600 PRINT@0,"Level";
610 PRINT@64,"Answers   0";
620 RETURN
700 IF X=0 THEN 750
710 IF X>0 THEN I(L)=13:GOTO 750
720 X=-X
730 IF I(L)>X THEN I(L)=13 ELSE I(L)=I(L)+X
750 RETURN
